package com.heima.wemedia.oos;

import com.heima.file.service.FileStorageService;
import com.heima.wemedia.mapper.WmMaterialMapper;
import com.heima.wemedia.service.WmNewsService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.io.IOException;

@SpringBootTest
public class ReptilesArticleData {
    @Autowired
    WmNewsService wmNewsService;
    @Resource
    WmMaterialMapper wmMaterialMapper;
    @Autowired
    FileStorageService fileStorageService;
    @Value("${file.oss.web-site}")
    String webSite;
    @Test
    public void reptilesData() throws IOException {

//        String url = "https://m.sohu.com/ch/13/?_f=m-index_history_hshd&spm=smwp.home.nav-ch.11.16379127161441jw8ENi";
        String url = "https://3g.163.com/touch/ent/?ver=c&clickfrom=index2018_header_main";
        Document document = Jsoup.connect(url).userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36")
                .get();
        document.select(".tab-content").stream().map(o->o.text()).forEach(System.out::println);
        Element channelFeed = document.getElementById("channelFeed");
        Elements elements = channelFeed.getElementsByClass("feed-item-scoped");
        System.out.println(elements.size());
        for (Element element : elements) {
            System.out.println(element.text());
        }
//        Elements elementsByClass = document.getElementsByClass("feed-item-scoped");
//        System.out.println("div元素个数:  " + elementsByClass.size());
//        Element element = elementsByClass.get(0);
        // 找到所有article标签页面元素
//        Elements articleList = ((Element) element).getElementsByTag("article");
//        for (Element article : articleList) {
//            Element aElement = article.getElementsByTag("a").get(0);
//            String href = aElement.attr("href");
//            System.out.println("新闻的url路径: "+href);
//            Element titleEle = aElement.getElementsByClass("title").get(0);
//            String title = titleEle.text();
//            System.out.println("新闻的文章标题:"+title);
//            Element newsPic = aElement.getElementsByClass("news-pic").get(0);
//            // 获取封面图片元素集合
//            Elements imgList = newsPic.getElementsByTag("img");

            // 封面图片集合

        }


    }



